home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / UNSUPERV / OJAS.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.9 KB  |  60 lines

  1. // Dynamic link library implementation of NeuroSolutions OjasFull component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /*************************************************************/
  6. /* Macros to access the PE layers and weights in matrix form */
  7.  
  8. #define in(i,j)        input[j+i*inCols]
  9. #define out(i,j)    output[j+i*outCols]
  10. #define W(i,j)        weights[j+i*inCount]
  11.  
  12. /******************************/
  13. /* Unsupervised weight update */
  14.  
  15. __declspec(dllexport) void performUnsupervised(
  16.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  17.     NSFloat    *input,        // Pointer to input layer 
  18.     int     inRows,        // Number of rows of PEs in the input layer
  19.     int     inCols,        // Number of columns of PEs in the input layer
  20.     NSFloat    *output,     // Pointer to the output layer
  21.     int     outRows,    // Number of rows of PEs in the output layer
  22.     int     outCols,    // Number of columns of PEs in the output layer
  23.     NSFloat    *weights,    // Pointer to fully connected weight matrix 
  24.     NSFloat    step         // Learning rate
  25.     )
  26. {
  27.     int    i, j,
  28.         inCount=inRows*inCols,
  29.         outCount=outRows*outCols;
  30.     NSFloat partialSum;
  31.  
  32.     for (j=0; j<inCount; j++) {
  33.         partialSum = (NSFloat)0;
  34.         for (i=0; i<outCount; i++)
  35.             partialSum += output[i] * W(i,j);
  36.         for (i=0; i<outCount; i++)
  37.             W(i,j) += step*output[i]*(input[j] - partialSum);
  38.     }
  39. }
  40.  
  41. /******************************************/
  42. /* Management of instance data (OPTIONAL) */
  43. /*
  44. __declspec(dllexport) DLLData *allocUnsupervised(
  45.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  46.     int     inRows,        // Number of rows of PEs in the input layer
  47.     int     inCols,        // Number of columns of PEs in the input layer
  48.     int     outRows,    // Number of rows of PEs in the output layer
  49.     int     outCols        // Number of columns of PEs in the output layer
  50.     )
  51. {
  52.     DLLData *instance = allocDLLInstance(oldInstance);
  53.     return instance;
  54. }
  55.  
  56. __declspec(dllexport) void freeUnsupervised(DLLData *instance)
  57. {
  58.     freeDLLInstance(instance);
  59. }
  60. */